<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="component.crossdomain.CrossDomainConstant"%>

<%
	response.addHeader("P3P", "CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR");
	
	String JSESSIONID = request.getSession().getId();//获取当前JSESSIONID （不管是从主域还是二级域访问产生）
	System.out.println("domainTo的JSESSIONID = " + JSESSIONID);

	String userId = (String)session.getAttribute("userId");
	if(userId == null) {
		System.out.println("第一次访问");
		session.setAttribute("userId","test");
	} else {
		System.out.println("第n次访问userId = " + userId);
	}
%>


JSESSIONID：<input type="text" value="<%=JSESSIONID%>" size="50"/> <br>
userId：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="userId" value="<%=userId%>" /> <br>

<input type="button" value="设置location.hash的值" onclick="callBack()" />

<iframe id="middleFrame" src="<%=CrossDomainConstant.DOMAIN_URL_FROM%>/crossdomain/test3/middle.html" style="visibility: hidden;"></iframe>


<script>

var locationHash = location.hash;
var locationHash_ = locationHash.substring(1,locationHash.length);
alert(locationHash + "\n" + locationHash_);

function callBack(){
    try {
        parent.location.hash = 'somedata';
    } catch (e) {
        // ie、chrome的安全机制无法修改parent.location.hash, 所以要利用一个中间的from域下的代理iframe
        var userId = document.getElementById("userId").value;
        var ifrproxy = document.getElementById("middleFrame");
        ifrproxy.src = "<%=CrossDomainConstant.DOMAIN_URL_FROM%>/crossdomain/test3/middle.html#" + userId;  // 注意该文件在源域下
        ifrproxy.location.reload();
    }
}

</script>